package com.yzf.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.yzf.entity.IdeaComment;
import com.yzf.util.db.DBHelp;
import com.yzf.util.db.RowMapper;

public class IdeaCommentDao {
	
	DBHelp<IdeaComment> db = new DBHelp<IdeaComment>();
	
	public void save(IdeaComment ideaComment){
		String sql = "insert into t_ideacomment (id,content,createtime,employeeid,ideaid) values(?,?,?,?,?)";
		db.executeSQL(sql, ideaComment.getId(),ideaComment.getContent(),ideaComment.getCreatetime(),ideaComment.getEmployeeid(),ideaComment.getIdeaid());
	}
	public List<IdeaComment> findByEidIid(String eid,String iid){
		String sql = "select id,content,createtime,employeeid,ideaid from t_ideacomment where employeeid=? and ideaid=? order by createtime desc";
		return db.executeQueryToList(sql, new IdeaCommentRowMapper(), eid,iid);
	}
	public void delete(String id){
		String sql = "delete from t_ideacomment where id =?";
		db.executeSQL(sql, id);
	}
	public IdeaComment findById(String id) {
		String sql = "select id,content,createtime,employeeid,ideaid from t_ideacomment where id=?";
		return db.executeQueryToObject(sql, new IdeaCommentRowMapper(), id);
	}
	public class IdeaCommentRowMapper implements RowMapper<IdeaComment>{

		@Override
		public IdeaComment mapRow(ResultSet rs) throws SQLException {
			
			IdeaComment comment = new IdeaComment();
			
			comment.setId(rs.getString("id"));
			comment.setContent(rs.getString("content"));
			comment.setCreatetime(rs.getString("createtime"));
			comment.setEmployeeid(rs.getString("employeeid"));
			comment.setIdeaid(rs.getString("ideaid"));
			return comment;
		}
		
		
	}
	
}
